/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Bussiness;

import Connection.Admin;
import Connection.DBUtil;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
/**
 *
 * @author SONY
 */
public class AdminDAO {
    private static Connection conn = null;
    private static CallableStatement cs = null;
    private static ResultSet rs = null;
    private static Admin objAdmin = null;
    private static DBUtil db = new DBUtil();
    
    public AdminDAO(){
    }
    public static Admin getAllAdmin(String email){
       try {
            conn = db.connect();
            cs = conn.prepareCall("{call spGetAdmin(?)}");
            cs.setString(1, email);
            rs = cs.executeQuery();
            while (rs.next()) {
                objAdmin = new Admin();
                objAdmin.setStt(rs.getInt(1));
                objAdmin.setEmail(rs.getString(2));
                objAdmin.setPassword(rs.getString(3));
                objAdmin.setFullName(rs.getString(4));
            }
        } catch (SQLException ex) {
        }
        return objAdmin;
    }
    
    public static void ChangePassword(String oldPassword, String newPassword){
        try{
            conn = db.connect();
            cs = conn.prepareCall("{call spChangePasswordAdmin(?,?)}");
            cs.setString(1, oldPassword);
            cs.setString(2, newPassword);
            cs.executeUpdate();
        } catch(Exception ex){
            ex.printStackTrace();
        }
    }
}
